<template>
	<view style="width: 100%;">
		<view class="input_view">
			<input class="input" :placeholder="cnObj.oldtip" v-model="oldpwd" password="true"/>
		</view>
		<view class="input_view">
			<input class="input" :placeholder="cnObj.new1tip" v-model="newpwd1" password="true"/>
		</view>
		<view class="input_view">
			<input class="input" :placeholder="cnObj.new2tip" v-model="newpwd2" password="true"/>
		</view>
		<view style="padding: 0 10px; width:calc(100% - 20px);" >
			<button type="primary" style="background-color: ##007AFF;color: #fff;border: none;" @click="submitpwd">{{cnObj.submittitle}}</button>
		</view>
	</view>
</template>

<script>
	var util = require("../../utils/util.js");
	var infolistutil = require("../../utils/infolistutil.js");
	var common = require("../../utils/api/common.js")
	const app = getApp().globalData;
	export default {
		data() {
			return {
				oldpwd:'',
				newpwd1:'',
				newpwd2:'',
				enObj:{'oldtip':'Your old password','new1tip':'New password of 6-30 digits','new2tip':'New password of 6-30 digits again','submittitle':'Submit',
						'prompt':'Prompt','pt1':'Password inconsistency','pt2':'Password changed successfully','load':'Loading'},
				cnObj:{'oldtip':'请输入您的旧密码','new1tip':'请输入您要设置的6-30位新密码','new2tip':'请再次输入您要设置的6-30位新密码','submittitle':'提交',
						'prompt':'提示','pt1':'密码不一致','pt2':'密码修改成功','load':'加载中'}
				
			}
		},
		
		onLoad:function(options){
			let i18n = uni.getStorageSync('i18n')
			if(i18n === 'en'){
				this.cnObj = this.enObj
				uni.setNavigationBarTitle({title:'Change password'})
			}
		},
		
		methods:{
			async submitpwd(){
				var that = this
				let i18n = uni.getStorageSync('i18n')
				
				var that = this
				var oldpwd = that.oldpwd
				var newpwd1 = that.newpwd1
				var newpwd2 = that.newpwd2
				if(newpwd1 != newpwd2){
					uni.showModal({
						title:that.cnObj.prompt ,
						content: that.cnObj.pt1,
						showCancel:false
					});
				}else{
				
					var injson = common.requestPassword(oldpwd, newpwd1)
					console.log(injson)
					uni.showLoading({title:that.cnObj.load})
					// var url = getApp().globalData.app_address + '?method=saas_ChangePassword&parse=json'
					var url = getApp().globalData.app_address + '?method=saas_UserPasswordModify&parse=json'
					const { data: res } = await infolistutil.post2(url, injson);
					var result = res
					uni.hideLoading()
					console.log(result)
					if(result.rtn!=1){
						let i18nArr = uni.getStorageSync('i18nArr')
						let errMsg = result.errMsg
						if(i18n === 'en' && i18nArr!=undefined){
							errMsg = that.$translg(errMsg,i18nArr)
						}
						uni.showModal({
							title: that.cnObj.prompt,
							content:errMsg,
							showCancel:false
						});
					}else{
						uni.showToast({title:that.cnObj.pt2})
						uni.navigateBack({
							delta:1
						})
					}
				}
			}
		}
	}
</script>

<style>
	.input_view{margin: 10px;padding: 5px 10px;border: 1px solid #D9D9D9;width:calc(100vw - 40px);border-radius: 5px;}
	.input{outline-color: invert;flex:1; outline-style: none;outline-width: 0px;border: none;border-style: none;text-shadow: none; -webkit-appearance: none;-webkit-user-select: text;outline-color: transparent;box-shadow: none;outline: none;border-radius: 0;}
</style>
